package com.twu.biblioteca;

public class MenuState implements State {
    private static MenuState menuStateInstance;
    String[] menuOptions = new String[]{"0. Display Books", "1. Check Membership"};

    private MenuState() {

    }

    public static synchronized MenuState getMenuStateInstance() {
        if (menuStateInstance == null) {
            menuStateInstance = new MenuState();
        }

        return menuStateInstance;

    }

    @Override
    public String displayWelcomeMessage() {
        return "Welcome!";
    }

    @Override
    public String displayMenuOptions() {
        String message = new String();

        for (String option : menuOptions) message = message + option + "\n";

        return message;
    }

    @Override
    public State change(String userInput) {

        if (userInput.equals("0"))
            return DisplayBooksState.getDisplayBooksStateInstance();
        else if (userInput.equals("1"))
            return MembershipInformationState.getMembershipInformationStateInstance();
        else if (userInput.equals("2"))
            return ReserveBookState.getReserveBookStateInstance();

        if (!userInput.equals("q"))
            System.out.println(INVALID_INPUT);
        return MenuState.getMenuStateInstance();  //To change body of implemented methods use File | Settings | File Templates.

    }
}
